package com.imau.brand.service.impl;

import com.imau.brand.bean.Brand;
import com.imau.brand.mapper.BrandMapper;
import com.imau.brand.service.BrandService;
import com.imau.brand.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class BrandServiceImpl implements BrandService {

    private SqlSession sqlSession;
    /**初始化持久层对象*/
    private BrandMapper brandMapper;

    public BrandServiceImpl()
    {
        sqlSession = SqlSessionUtil.getSqlSession();
        brandMapper = sqlSession.getMapper(BrandMapper.class);
    }
    @Override
    public boolean saveBrand(Brand brand) {
        int row = brandMapper.addBrand(brand);
        return row > 0;
    }

    @Override
    public boolean editBrand(Brand brand) {
        return brandMapper.updateBrand(brand) > 0;
    }

    @Override
    public boolean dleBrand(Integer id) {
        return brandMapper.deleteById(id) > 0;
    }

    @Override
    public Brand findById(Integer id) {
        return  brandMapper.selectById(id);
    }

    @Override
    public List<Brand> findAll() {
        return brandMapper.selectAll();
    }
}
